﻿// JScript 文件
CreateGoogle(160,600,null,null,null,null,null,null,null,null);
var gPageIndex=1;
function pageLoad(sender, args) 
{
    if(typeof(commentPage) != "undefined")
    {
        RendPageNavigator(commentPage,"divPage","GetPageComment");
    }    
}
//初始数据
function onsuccComment(result)
{
   RendCommentList(result[1],"CommentList"); 
   RendPageNavigator(result[0],"divPage","GetPageComment"); 
   showProgressBar(false);
}
//获取数据（页索引）
function InitDataComment(pageIndex)
{
    WebServices.User.Learn.GetLearnMembersAndComment(learnL,pageIndex,20,onsuccComment);
}
//获取页面数据（页索引）
function GetPageComment(pageIndex)
{
	showProgressBar(true);
    gPageIndex = pageIndex;
    InitDataComment(gPageIndex);
}
function RendCommentList(list,divID)
{
    var domDiv = $get(divID);    
    if(domDiv!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }        
        if($get("CommentTemplate")==null) return;        
        var item= $get("CommentTemplate").innerHTML;
        var listBuilder = new Sys.StringBuilder();        
        for (var index = 0; index < list.length; index++) 
        {
            var obj = list[index];            
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.Avatar==""?"/Images/No_pic.gif":obj.Avatar)+"\"/>").replace(/\$Memberno\$/gi,obj.Memberno);
            tmp = tmp.replace(/\$NickName\$/gi,obj.Nickname).replace(/\$Content\$/gi,obj.Content.replace(/\n/gi,'<br/>'));
            tmp = tmp.replace(/\$whopost\$/gi,C0090.replace("{0}","<a href='/"+obj.Memberno+".htm'>"+obj.Nickname+"</a>"));
            var arr1 = gDateFormat.split(":");
            var arr2 = obj.DiffDate.split(":");
            if(arr2[0]>0)
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,gStrDate1.replace("{0}",arr2[0]).replace("{1}",arr1[0]));
            }
            else if(arr2[1]>0)
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,gStrDate1.replace("{0}",arr2[1]).replace("{1}",arr1[1]));
            }
            else if(arr2[2]>0)
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,gStrDate1.replace("{0}",arr2[2]).replace("{1}",arr1[2]));
            }
            else if(arr2[3]>0)
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,gStrDate1.replace("{0}",arr2[3]).replace("{1}",arr1[3]));
            }
            else if(arr2[4]>0)
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,gStrDate1.replace("{0}",arr2[4]).replace("{1}",arr1[4]));
            }
            else if(arr2[5]>0)
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,gStrDate1.replace("{0}",arr2[5]).replace("{1}",arr1[5]));
            }
            else
            {
                tmp = tmp.replace(/\$CreateDate\$/gi,"");
            }
            listBuilder.append(tmp);
        }
        var sTemp = listBuilder.toString();       
        domDiv.innerHTML = sTemp;
    }
}

//添加学习评论
function AddComment()
{
    if(!memberno||memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    } 
    if(!$ValidButton$())return;
    $get("btnPost").disabled = true;
    showProgressBar(true);
    WebServices.User.Learn.AddComments(learnL,$get("txtLc").value,memberno,onsuccOP);
    $get("txtLc").value = "";
}

function onsuccOP(result,cmp)
{
    $get("btnPost").disabled = false;
    showProgressBar(false);
    Sys.UI.DomElement.removeCssClass($get("MainMessagePanel"), "DisplayNone");
    if(result.State) 
    {   
        $get("MessageImg").src = MessageImageS;
        $get("MessageText").innerHTML = MessageTextS;
        InitDataComment(gPageIndex);
    }
    else
    {
        $get("MessageImg").src = MessageImageF;
        $get("MessageText").innerHTML = MessageTextF; 
    }
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
